{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv(\"../raw-datasets/energy_dataset.csv\")\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Select only the columns we need\n",
    "df = df[[\"time\", \"price actual\"]]\n",
    "\n",
    "# Drop NaN values\n",
    "df = df[[\"time\", \"price actual\"]].dropna()\n",
    "\n",
    "# Rename columns ds and y\n",
    "df = df.rename(columns={\"time\": \"ds\", \"price actual\": \"y\"})\n",
    "\n",
    "# Convert to datetime\n",
    "df[\"ds\"] = pd.to_datetime(df[\"ds\"], utc=True).dt.tz_localize(None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Export full resolution dataset (hourly)\n",
    "\n",
    "df.to_csv(\"../datasets/tutorial01-full.csv\", index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Export simplified dataset with one value per day\n",
    "\n",
    "df.set_index('ds').resample('1D').mean().reset_index().round({'y': 2}).to_csv(\"../datasets/tutorial01.csv\", index=False)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Tutorial 4\n",
    "\n",
    "Add lagged regressor column to the previous dataset subset."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_weather = pd.read_csv(\"../raw-datasets/weather_features.csv\")\n",
    "df_weather.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_weather = df_weather.reset_index()\n",
    "\n",
    "# Select only the columns we need\n",
    "df_weather = df_weather[[\"dt_iso\", \"temp\"]]\n",
    "\n",
    "# Drop NaN values\n",
    "df_weather = df_weather.dropna()\n",
    "\n",
    "# Rename columns ds and y\n",
    "df_weather = df_weather.rename(columns={\"dt_iso\": \"ds\", \"temp\": \"temperature\"})\n",
    "\n",
    "# Convert to datetime\n",
    "df_weather[\"ds\"] = pd.to_datetime(df_weather[\"ds\"], utc=True).dt.tz_localize(None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_weather = df_weather.set_index('ds').resample('1D').mean().reset_index().round({'temperature': 2})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df2 = pd.merge(df, df_weather, on=\"ds\")\n",
    "df2.to_csv(\"../datasets/tutorial04.csv\", index=False)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.10.8 ('.venv': venv)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.10"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "d6ec467f3019c3da38ba075f32e063fa1433d1ac8bb717541f5aa7b18909edd9"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
